﻿#ifndef XQHTTPREPLYOBJECT_H
#define XQHTTPREPLYOBJECT_H
#include"XQHttpHeadReply.h"
#include"XQLogDebug.h"
#include<QObject>
#include<QEvent>
class XQHttpHeadRequest;
class QIODevice;
QEvent HttpResponseEvent();
//http 回应模式基类
class XQHttpReplyObject :public QObject,public XQLogDebug
{
	Q_OBJECT
public:
	XQHttpReplyObject(QObject* parent = nullptr);
	virtual ~XQHttpReplyObject() {};
	friend class XQHttpServer;
	friend class XQHttpClient;
public:
	virtual QByteArray appName()const;
	QString name()const ;
	//获取目录
	QString dir()const;
	//获取地址 dir+p  获得 传入的路径+设置的目录
	QString path(const QString& p)const;
public:
	virtual void setName(const QString& name);
	//绑定外部名字使用     nullptr重新绑定回内部的
	void bindName(QString* name);
	//绑定目录
	virtual void bindDir(QString* dir);
protected:
	//是否接受
	virtual bool isAccepted(XQHttpHeadObject* head) const;
	//接收请求完毕处理回复
	virtual XQHttpHeadReply reply(QIODevice* socket, XQHttpHeadRequest* header);
	//接收请求中 缓存处理
	virtual void buffer(QIODevice* socket, XQHttpHeadObject* head, const QByteArray& buffer);
	//有客户端链接到来
	virtual void clientConnected(QIODevice* socket);
	//有客户端断开连接
	virtual void clientdisconnected(QIODevice* socket);
protected:
	QString m_name;//名称
	QString* m_pName = &m_name;//绑定名称
	QString* m_dir=nullptr;//设置的目录
};
#endif // !XQHttpReply_H
